package com.atguigu.classroom.wechat.controller;


import com.atguigu.classroom.model.wechat.Menu;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.wechat.MenuVo;
import com.atguigu.classroom.wechat.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单明细 订单明细 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-07-17
 */
@Api(tags = "微信公众号接口")
@RestController
@RequestMapping("/admin/wechat/menu/")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @ApiOperation("根据id查询")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        return Result.ok(menuService.getById(id));
    }
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result save(@RequestBody Menu menu) {
        menuService.save(menu);
        return Result.ok(null);
    }
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody Menu menu) {
        menuService.updateById(menu);
        return Result.ok(null);
    }
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        menuService.removeById(id);
        return Result.ok(null);
    }
    @ApiOperation(value = "根据id集合批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        menuService.removeByIds(idList);
        return Result.ok(null);
    }
    @ApiOperation("获取所有一级菜单")
    @GetMapping("findOneMenuInfo")
    public Result findOneMenuInfo(){
        List<Menu> menuList=menuService.findOneMenuInfo();
        return Result.ok(menuList);
    }
    @ApiOperation("获取所有菜单，并按照一级和二级菜单封装")
    @GetMapping("findMenuInfo")
    public Result findMenuInfo(){
        List<MenuVo> menuList=menuService.findMenuInfo();
        return Result.ok(menuList);
    }
    @ApiOperation("获取AccessToken")
    @GetMapping("getAccessToken")
    public Result getAccessToken(){
        String token=menuService.getAccessToken();
        return Result.ok(token);
    }
    @ApiOperation("同步菜单方法")
    @GetMapping("syncMenu")
    public Result syncMenu(){
        String menuId = menuService.syncMenu();
        return Result.ok(menuId);
    }
    @ApiOperation("公众号菜单删除")
    @DeleteMapping("removeMenu")
    public Result removeMenu(){
        menuService.removeMenu();
        return Result.ok(null);
    }
}

